/**
 *
 * @param {object} ops 接口查询参数
 * @object ops.letter 前置
 * @object ops.name 搜索名称
 * @param {*} callback
 */
function hangleFetchGameList(ops, callback) {
  const $ = layui.$
  const layer = layui.layer
  let URL = `/app/admin/v1-api/getGameList`

  if (ops) {
    let opsArrs = []
    for (const key in ops) {
      const value = ops[key]
      opsArrs.push(`${key}=${value}`)
    }
    URL += '?' + opsArrs.join('&')
  }

  layer.load()
  $.ajax({
    url: URL,
    type: 'GET',
    data: {},
    success: function (res) {
      layer.closeAll('loading')
      if (res.code) {
        layui.popup.failure(res.msg)
      }
      callback && callback(res.data || [])
    },
  })
}

function renderGamesElement(list = []) {
  if (!list.length) {
    layui
      .$('#gamelistbox')
      .html('<i style="color: #999; user-select: none">暂无游戏</i>')
    return
  }
  let $ = layui.$
  const parent = $('#gamelistbox')
  const fragement = new DocumentFragment()

  $.each(list, function (index, item) {
    fragement.appendChild(
      $(
        `<button plain class="pear-btn" data-id="${item.id}">${item.name}</button>`
      )[0]
    )
  })

  parent.html(fragement)
}
